//
//  UIColor+Utils.m
//  ifangchou
//
//  Created by Bias.Xie on 15/9/10.
//  Copyright (c) 2015年 ifangchou. All rights reserved.
//

#import "UIColor+Utils.h"

static NSMutableDictionary *sColorDictionary = nil;

@implementation UIColor (Utils)

+ (void)load{
    if( sColorDictionary == nil )
    {
        sColorDictionary = [[NSMutableDictionary alloc] initWithCapacity:100];
    }
}

+ (UIColor *)colorForHex:(NSString *)hexColor
{
    UIColor *color;
    
    color = [sColorDictionary objectForKey:hexColor];
    if( color ){
        return color;
    }

    
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [hexColor substringWithRange:range];
    range.location = 2;
    NSString *gString = [hexColor substringWithRange:range];
    range.location = 4;
    NSString *bString = [hexColor substringWithRange:range];
    range.location = 6;
    NSString *aString = [hexColor substringWithRange:range];

    
    unsigned int r, g, b, a;
    
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    [[NSScanner scannerWithString:aString] scanHexInt:&a];
    

    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:((float) a / 255.0f)];
}



+ (UIColor *)color_F79D31FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_2A3A47FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}


+ (UIColor *)color_444444FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_888888FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_CCCCCCFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_DDDDDDFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_EEEEEEFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_F7F7F7FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_C30029FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_00D48CFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_FFE7ACFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_747E86FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_26333FFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_F58500FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}


+ (UIColor *)color_FFFFFFFF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}

+ (UIColor *)color_FFA800FF{
    NSString *selString = NSStringFromSelector(_cmd);
    NSArray *valueArray = [selString componentsSeparatedByString:@"_"];
    NSString *hexColor = [valueArray objectAtIndex:1];
    return [self colorForHex:hexColor];
}


+ (UIColor *)colorForProjectStatus:(NSInteger)status{
    UIColor *color = [UIColor color_26333FFF];
    if( status == -1 ){
    }
    else if( status == 0 ){
    }
    else if( status == 1 ){
    }
    else if( status == 2 ){
        color = [UIColor color_F58500FF];
    }
    else if( status == 3 ){
    }
    else if( status == 4 ){
    }

    return color;
}

+ (UIColor *)colorFromInteger:(NSInteger)num
{
    switch (num) {
        case 1:
            return BG_COLOR;
            break;
        case 2:
            return BG_TRANSLUCENT;
            break;
        case 3:
            return CUSTOM_LIGHT_GRAY;
            break;
        case 4:
            return CUSTOM_LIGHT_GRAY_2;
            break;
        case 5:
            return CUSTOM_LIGHT_GRAY_3;
            break;
        case 6:
            return CUSTOM_LIGHT_GRAY_4;
            break;
        case 7:
            return CUSTOM_LIGHT_ORANGE;
            break;
        case 8:
            return CUSTOM_LIGHT_ORANGE_2;
            break;
        case 9:
            return CUSTOM_LIGHT_ORANGE_3;
            break;
        case 10:
            return CUSTOM_LIGHT_BLUE;
            break;
        case 11:
            return CUSTOM_LIGHT_GREEN;
            break;
        case 12:
            return CUSTOM_LIGHT_BLUE_2;
            break;
        case 13:
            return DEEP_BLUE;
            break;
        case 14:
            return DEEP_GREEN_COLOR;
            break;
        case 15:
            return DEEP_GREEN_COLOR_2;
            break;
        case 16:
            return MAIN_COLOR;
            break;
        case 17:
            return CELL_BG_COLOR;
            break;
        case 18:
            return LINE_BG_COLOR;
            break;
        case 19:
            return LINE_BG_COLOR_2;
            break;
        case 20:
            return WHITE_COLOR;
            break;
        case 21:
            return BLACK_COLOR;
            break;
        case 22:
            return CLEAR_COLOR;
            break;
        case 23:
            return ORANGE_COLOR;
            break;
        case 24:
            return GREEN_COLOR;
            break;
        case 25:
            return BLUE_COLOR;
            break;
        case 26:
            return BG_TRANSLUCENT_2;
            break;
        case 27:
            return BG_STR_CONTENT;
            break;
        case 28:
            return BLACK_TITILE_COLOR;
            break;
        case 29:
            return BLACK_TITILE_COLOR_2;
            break;
        case 30:
            return BLACK_TITILE_COLOR_3;
            break;
        case 31:
            return POPBG_COLOR;
        case 32:
            return ORANGE_COLOR_2;
        case 33:
            return CUSTOM_LIGHT_GRAY_5;
        default:
            break;
    }
    return CLEAR_COLOR;
}

@end
